package com.songlanyun.common.supplychainapi.aftersale;


import com.jxhh.ApiClient;
import com.songlanyun.common.supplychainapi.aftersale.model.*;
import com.songlanyun.common.supplychainapi.aftersale.model.BeforeCheck;
import com.songlanyun.common.supplychainapi.common.ApiRequestCommon;
import com.songlanyun.common.supplychainapi.common.ResultCommon;
import com.songlanyun.common.supplychainapi.order.model.*;
import com.songlanyun.common.utils.custom.ClassConvertUtils;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@Component
public class ApiAfterSaleCommon {

    /**
     * 售后前置校验V2
     */
    private static final String BEFORE_CHECK_URL = "/v2/afterSale/beforeCheck";
    /**
     * 上传售后凭证（图片）V2
     */
    private static final String AFTER_SALE_PICTURE_URL = "/v2/afterSale/picture";
    /**
     * 申请售后V2
     */
    private static final String AFTER_SALE_URL = "/v2/afterSale";


    @Resource
    private ApiRequestCommon request;

    /**
     * 售后前置校验V2
     *
     * @param beforeCheckParam
     * @return
     */
    public BeforeCheck beforeCheck(BeforeCheckParam beforeCheckParam) {
        Map<String, Object> params = ClassConvertUtils.transformObject(beforeCheckParam, Map.class);
        return request.exec(BEFORE_CHECK_URL, ApiClient.RequestMethod.POST, params, BeforeCheck.class, "售后前置校验");
    }

    /**
     * 上传售后凭证（图片）V2
     *
     * @param afterSalePictureParam
     * @return
     */
    public AfterSalePicture afterSalePicture(AfterSalePictureParam afterSalePictureParam) {
        Map<String, Object> params = ClassConvertUtils.transformObject(afterSalePictureParam, Map.class);
        return request.exec(AFTER_SALE_PICTURE_URL, ApiClient.RequestMethod.POST, params, AfterSalePicture.class, "上传售后凭证（图片）");
    }

    /**
     * 申请售后V2
     *
     * @param afterSaleParam
     * @return
     */
    public AfterSale afterSale(AfterSaleParam afterSaleParam) {
        Map<String, Object> params = ClassConvertUtils.transformObject(afterSaleParam, Map.class);
        return request.exec(AFTER_SALE_URL, ApiClient.RequestMethod.POST, params, AfterSale.class, "申请售后");
    }

    /**
     * 售后列表V2
     *
     * @param params
     * @return
     */
    public AfterSaleList afterSaleList(Map<String, Object> params) {
        return request.exec(AFTER_SALE_URL, ApiClient.RequestMethod.GET, params, AfterSaleList.class, "售后列表");
    }

    /**
     * 售后详情V2
     *
     * @param id
     * @return
     */
    public AfterSaleInfo afterSaleInfo(String id) {
        return request.exec(AFTER_SALE_URL + "/" + id, ApiClient.RequestMethod.GET, new HashMap<>(), AfterSaleInfo.class, "售后详情");
    }

    /**
     * 退货商家邮寄信息
     *
     * @param afterSaleMailParam
     * @return
     */
    public void afterSaleMail(AfterSaleMailParam afterSaleMailParam) {
        Map<String, Object> params = ClassConvertUtils.transformObject(afterSaleMailParam, Map.class);
        request.exec(AFTER_SALE_URL, ApiClient.RequestMethod.PATCH, params, null, "退货商家邮寄信息");
    }

}
